package main

import (
	"bufio"
	"fmt"
	"net"
	"os"
	"strings"
)

func main() {
	conn, connErr := net.Dial("tcp", "127.0.0.1:8888")
	defer conn.Close()
	if connErr != nil {
		fmt.Printf("connect error : %v", connErr)
	}
	inputReader := bufio.NewReader(os.Stdin)
	for {
		line, readErr := inputReader.ReadString('\n')
		if readErr != nil {
			fmt.Printf("read error : %v", readErr)
			return
		}
		line = strings.Trim(line, "\r\n")
		if line == "exit" {
			return
		}
		n, sendErr := conn.Write([]byte(line))
		if sendErr != nil {
			fmt.Printf("sendErr error : %v", sendErr)
			return
		}
		fmt.Printf("send %d bytes \n", n)
	}
}
